using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json.Linq;
using System;

public class InventoryManager 
{
    public Transform PickedItem;
    public Transform Panel;
    List<Item> items = new List<Item>();
    public Inventory inventory;
    
    public bool Canshoot = true;
    public InventoryManager()
    {
        inventory = new Inventory();
   
    }
    public void GameIn()
    {
        Panel = GameFacade.Instance.uIset.Bag.Find("Panel");
        PickedItem = GameFacade.Instance.uIset.Bag.Find("PickItem");
    }
     Item Read(JObject jarray)
    {
        int Id = (int)jarray["Id"];
        string Name = (string)jarray["Name"];
        string Path = (string)jarray["Sprite"];
        int Attack = (int)jarray["Attack"];
        int capacity = (int)jarray["Capacity"];
        Category ItemTypes = (Category)Enum.Parse(typeof(Category), (string)jarray["Category"]);
        Item item = new Item(Id, Name, Path,Attack, capacity, ItemTypes);
        
        return item;
    }
    public void ToJoson()
    {
        TextAsset Text = Resources.Load<TextAsset>("Text/Item");
        string json = Text.text;
        JArray jArray = JArray.Parse(json);
        foreach (JObject jarray in jArray)
        {
            Item item = Read(jarray);
            items.Add(item);
        }
    }
    public Item Getitem(int id)
    {
        foreach (Item item in items)
        {
            if (id == item.Id)
            {
                return item;
            }
        }
        return null;
    }
    public int ReturnCapacity(Item item)
    {
        foreach (Item items in items)
        {
            if (item == items)
            {
                return items.Capacity;
            }
        }
        return 0;
    }
}
